#include <jni.h>
#include <android/bitmap.h>
#include <include/core/SkBitmap.h>
#include <include/core/SkCanvas.h>
#include <include/core/SkTypeface.h>
#include <include/core/SkFont.h>

#include <JSExports.h>

using namespace js_export;

extern "C"
JNIEXPORT void JNICALL
Java_pub_doric_extension_SkiaView_nativeRender(
        JNIEnv *env,
        jobject thiz,
        jobject bitmap) {

    AndroidBitmapInfo info;
    int *pixel;
    int ret;

    ret = AndroidBitmap_getInfo(env, bitmap, &info);
    ret = AndroidBitmap_lockPixels(env, bitmap, (void **) &pixel);

    int width = info.width;
    int height = info.height;

    SkBitmap bm = SkBitmap();
    SkImageInfo image_info = SkImageInfo
    ::MakeS32(width, height, SkAlphaType::kOpaque_SkAlphaType);
    bm.setInfo(image_info, image_info.minRowBytes());
    bm.setPixels(pixel);

    SkCanvas background(bm);
    SkPaint paint;//画笔

    paint.setColor(SK_ColorBLACK);
    SkRect rect;//绘制一个矩形区域
    rect.set(SkIRect::MakeWH(width, height));

    background.drawRect(rect, paint);

    SkPaint paint2;
    paint2.setColor(SK_ColorBLUE);
    const char *str = "Hello Skia";

    SkFont skfont(SkTypeface::MakeDefault(), 100);

    background.drawString(str, 100, 100, skfont, paint2);

    AndroidBitmap_unlockPixels(env, bitmap);
}

JSValue *nativeCall(JSValue *args[], int argsSize) {

}

extern "C"
JNIEXPORT jlong JNICALL
Java_pub_doric_extension_SkiaJNI_getNativeCall(JNIEnv *env, jclass clazz) {
    return (jlong) nativeCall;
}